const {database} = require('../config')
const mongoose = require('mongoose')
mongoose.connect(`mongodb://${database.user}:${database.pwd}@${database.host}:${database.port}/${database.db}`, { useNewUrlParser: true })
const db = mongoose.connection

db.on('error', console.error.bind(console, 'connection error:'))
db.once('open', ()=>{console.log(' MongoDB connected!')})
db.on('disconnected', ()=>{console.log(' MongoDB disconnected!')})

const Schema = mongoose.Schema

module.exports = {
    mongoose,
    Schema
}